﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Globalization;
using OpenPhotoAlbum.Controls;

namespace OpenPhotoAlbum.Shared
{
	public partial class Album : AlbumPage
	{
		protected override void OnInit(EventArgs e)
		{
			base.OnInit(e);

			this.Title = StringUtility.Format(Resources.Strings.Title_Shared_Album, this.CurrentAlbum.AlbumTitle);
		}

        protected override void AppendSiteMapNodes(OpenPhotoAlbum.Controls.AlbumSiteMapProvider provider)
        {
            base.AppendSiteMapNodes(provider);

            provider.AppendSiteMapNode(Resources.Strings.SC_Home, Links.Default);
            provider.AppendSiteMapNode(
                StringUtility.Format(Resources.Strings.Shared_Title, this.AlbumOwner.UserName),
                UrlContext.BuildSharedHomeUrl(this.AlbumOwner.UserId));
            provider.AppendSiteMapNode(this.CurrentAlbum.AlbumTitle, RawUrl);
        }

		public DbAccess.User AlbumOwner
		{
			get
			{
				Shared masterPage = this.Master as Shared;
				if (masterPage == null) { return null; }

				DbAccess.User user = masterPage.User;
				if (user == null) { return null; }

				return user;
			}
		}

		private DbAccess.Album _album = null;

		public DbAccess.Album CurrentAlbum
		{
			get
			{
				if (_album == null)
				{
					_album = BusinessLogics.AlbumManager.Instance.GetAlbum(UrlContext.AlbumId);
				}
				return _album;
			}
		}
	}
}
